#encoding=utf-8
'''
Created on 2014-12-9

@author: cooler
'''
import sys
reload(sys)
sys.setdefaultencoding('utf8')
import  logging

# send email
import smtplib
from email.mime.text import MIMEText
from email.Header import Header
from email.MIMEMultipart import MIMEMultipart

logger = logging.getLogger('Email')
logger.setLevel(logging.DEBUG)


def send_mail(to_list,subject,content):
    #####################
    # 设置服务器，用户名、口令以及邮箱的后缀
    mail_host="smtp.163.com"
    mail_user="safeisland"
    mail_pass="19861217"
    mail_postfix="163.com"
    ######################
    me=mail_user+"<"+mail_user+"@"+mail_postfix+">"
    msg = MIMEText(content,'html', 'utf-8')
    msg['Subject'] = subject
    msg['From'] = me
    msg['To'] = ";".join(to_list)
    try:
        s = smtplib.SMTP()
        s.connect(mail_host)
        s.login(mail_user,mail_pass)
        s.sendmail(me, to_list, msg.as_string())
        s.close()
        return True
    except Exception, e:
        # print str(e)
        return False